using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using OpenProject.DataObjects;
namespace OpenProject.Web
{
    public class SiteUtilities
    {
        /// <summary>
        /// This is the Role that we evaluate for CMS editing privvies
        /// Change as needed
        /// </summary>
        const string CONTENT_EDITOR_ROLE = "Content Editor";

        public static bool UserCanEdit()
        {
            return HttpContext.Current.User.IsInRole(CONTENT_EDITOR_ROLE);
        }

        public static string ProjectTitle
        {
            get
            {
                string title = HttpContext.Current.Request.QueryString["ProjectTitle"];
                if(title == null)
                    return "";
                return title;
            }
        }
        public static int ProjectId
        {
            get
            {
                return ProjectController.ProjectIdFromProjectTitle(ProjectTitle);
            }
        }
        public static int UserId
        {
            get
            {
                MembershipUser user = System.Web.Security.Membership.GetUser();
                if (user != null)
                   return (int)user.ProviderUserKey;
                else
                    return 0;
            }
        }
        public static string PageUrl
        {
            get
            {
                return HttpContext.Current.Request.QueryString["PageUrl"].ToString();
            }
        }
    }
}